class EndLessAccountUI extends UIBase{
    private lb_tips:eui.Label;
    private lb_score:eui.Label;
    private lb_total:eui.Label;
    private lb_need:eui.Label;

    private btn_sure:BaseButton;
    constructor(data)
    {
        super('EndLessAccountView', data);
        SoundManager.instance().stop();
        SoundManager.instance().playSound('win_mp3', 1);
    }

    public init()
    {
        super.init(true);
        if(this.data)
        {
            this.sendToSever();
        }
    }

    public initUI(data)
    {
        if(data)
        {
            let count = this.data.count;
            let score = data.score;
            let total = data.all_score;
            let rank = data.rank;
            let apart_score = data.not_score;//相距前五名的分数
            EffectUtil.instance().NumChange(this.lb_tips, 0, count, 700, '您共切了','个水果');
            EffectUtil.instance().NumChange(this.lb_score, 0, score, 700, '','分');
            EffectUtil.instance().NumChange(this.lb_total, 0, total, 700, '','分');
            if(rank < 0 || rank > 5)
            this.lb_need.visible = false;
            if(rank == 5)
                EffectUtil.instance().NumChange(this.lb_need, 0, apart_score, 700, '距离第五名相差','分');
            else
                this.lb_need.text = '您已经位列前五甲之中了哦!';
        }
    }

    public sendToSever()
    {
        let data = {
            version:GameConst.version,
            num:this.data.count
        }
        let self = this;
        HttpManager.instance().sendPost(GameConst.httpUrl + 'warriorendless/balance' , StringUtil.jsonToHttpPostString(data), (e)=>{
            let data = JSON.parse(e);
            if(data && data.data)
            {
                let total = data.data.all_score;
                RankManager.instance().uploadUserScore(total,'points');
                self.initUI(data.data);
            }
        })
    }

    protected addEvent()
    {
        this.btn_sure.addTapHandler(this.backHome, this);
    }

    protected backHome()
    {
        ScreenMovies.MovieStart(2,()=>{
            let da = {
                index:0
            }
            UIManager.instance().openUILogic(MainUI, da);
        },this);
    }

    protected removeEvent()
    {
        this.btn_sure.removeTapHandler();
    }

    protected clear()
    {
        super.clear();
        EffectUtil.instance().StopEffect(this.lb_need);
        EffectUtil.instance().StopEffect(this.lb_score);
        EffectUtil.instance().StopEffect(this.lb_tips);
        EffectUtil.instance().StopEffect(this.lb_total);
    }
}